/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.sbbs.dao;

import java.util.List;
import javax.annotation.PostConstruct;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.sbbs.model.DemoEntity;

/**
 *
 * @author Mr.fdc <fdc_messenger@126.com>
 */
@Stateless
public class DemoEntityDaoEjb {

    @PersistenceContext(unitName = "DEFAULT")
    private EntityManager em;

    @PostConstruct
    public void init() {
    }

    public DemoEntity add(DemoEntity de) {
        return this.em.merge(de);
    }

    public DemoEntity find(Long id) {
        return this.em.find(DemoEntity.class, id);
    }

    public void delete(DemoEntity de) {
        this.em.remove(de);
    }

    public List<DemoEntity> findAll() {
        return this.em.createQuery("select t from DemoEntity t").getResultList();
    }
}
